package org.smr.ministore.micro;

import java.util.List;

import org.blade.dao.base.BaseMapper;
import org.blade.utils.IdGenUtils;
import org.smr.ministore.dao.GoodsMapper;
import org.smr.ministore.entities.Goods;
import org.smr.ministore.entities.GoodsOrgan;
import org.smr.ministore.entities.vo.Assign2OrganVO;
import org.smr.ministore.entities.vo.Assign2OrgansVO;
import org.smr.ministore.service.GoodsService;
import org.blade.service.base.AbstractService;

import org.blade.utils.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
public class GoodsMicroService extends AbstractService<Long, Goods> implements GoodsService {


    @Resource(name = "GoodsServiceFacade")
    private GoodsService goodsService;

    @Autowired
    public GoodsMicroService(GoodsMapper mapper) {
        super(mapper);
    }


    @Override
    @ResponseBody
	@RequestMapping(method = RequestMethod.POST, value = "/Goods/batchSave")
	public int batchSave(@RequestBody List<Goods> entities) {
        this.batchSaveAttatch(entities);
    	return goodsService.batchSave(entities);
    }

    @Override
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/Goods/batchModify")
    public int batchModify(List<Goods> entities) {
        this.batchModifyAttatch(entities);
        return goodsService.batchModify(entities);
    }

    @Override
    @ResponseBody
    @RequestMapping(method = RequestMethod.PUT, value = "/Goods/save")
    public int save(@RequestBody Goods entity) {
        this.saveAttatch(entity);
    	return goodsService.save(entity);
    }

    @Override
    @ResponseBody
    @RequestMapping(method = RequestMethod.PATCH, value = "/Goods/updateById")
    public int updateById(@RequestBody Goods id) {
        this.modifyAttach(id);
   	 	return goodsService.updateById(id);
    }

    @Override
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/Goods/queryById/{id}")
    public Goods queryById( @PathVariable("id")Long id ) {
    	return (Goods) goodsService.queryById(id);
    }

    @Override
    @ResponseBody
    @RequestMapping(method = RequestMethod.DELETE, value = "/Goods/deleteById/{id}")
    public int deleteById( @PathVariable("id")Long id ) {
        return goodsService.deleteById(id);
    }

    @Override
    @ResponseBody
    @RequestMapping( method = RequestMethod.POST, value = "/Goods/paginate/{pageSize}/{pageNum}")
    public Pager<Goods> paginate(@RequestBody Goods entity, @PathVariable("pageSize")Long pageSize,  @PathVariable("pageNum")Long pageNum ) {
        return this.goodsService.paginate( entity, pageSize,pageNum );
    }

    @Override
    @ResponseBody
    @RequestMapping( method = RequestMethod.POST, value = "/Goods/selectByPrimaryKey")
    public Goods queryByPrimaryKey(@RequestBody Goods entity) {
        return goodsService.queryByPrimaryKey(entity);
    }


    @Override
    @ResponseBody
    @RequestMapping(method = RequestMethod.DELETE, value = "/Goods/deleteByIdLogical/{id}")
    public int deleteByIdLogical(@PathVariable("id")Long id) {
        return goodsService.deleteByIdLogical(id);
    }

    @Override
    @ResponseBody
    @RequestMapping( method = RequestMethod.POST, value = "/Goods/assign2Organs")
    public int assign(@RequestBody Assign2OrgansVO assignee) {
        return goodsService.assign(assignee);
    }


    @Override
    @ResponseBody
    @RequestMapping( method = RequestMethod.POST, value = "/Goods/assign2Organ")
    public int assign(@RequestBody Assign2OrganVO goodsAssign2Organ) {
        return goodsService.assign(goodsAssign2Organ);
    }

    @Override
    @ResponseBody
    @RequestMapping( method = RequestMethod.POST, value = "/Goods/queryGoodsAssignee")
    public List<GoodsOrgan> queryGoodsAssignee(@RequestBody Assign2OrgansVO assignee) {
        return goodsService.queryGoodsAssignee(assignee);
    }

    @Override
    public Long getId() {
        return IdGenUtils.getNextLongId();
    }
}
